package util;

import java.awt.Component;
import java.awt.Cursor;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public final class GestorCursor {

    public final static Cursor busyCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
    public final static Cursor defaultCursor = Cursor.getDefaultCursor();

    private GestorCursor() {}

    public static ActionListener createListener(final Component component, final ActionListener mainActionListener) {
        ActionListener actionListener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                try {
                    component.setCursor(busyCursor);
                    mainActionListener.actionPerformed(ae);
                } finally {
                    component.setCursor(defaultCursor);
                }
            }
        };
        return actionListener;
    }
}